<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>异步加载图片</title>
    <style>
        
        img{

            width: 200px;
        }
    </style>
</head>
<body>
    <img src="images/1.jpg" alt="" id="img">
    <script>
        const gu=(url)=>{
            return new Promise((resolve,reject)=>{
                var img=new Image();
                img.onload=()=>{
                    resolve(img);
                };
                img.onerror=()=>{
                    reject(new Error(`error`));
                }
                img.src=url;
            })
        }
        var img2=document.getElementById('img')
        gu("images/pan.jpg").then((img)=>{
            console.log(img.src)
            setTimeout(()=>{img2.src=img.src},1000)
       
        }).catch(err=>{
            console.log(err)
        })

    
    </script>
</body>
</html>